<?php


class SiteController extends Controller
{
	public $code_url;
	
	
	public function actions()
    {
        return array(
            'index'=>'application.controllers.actions.dz.PostDzAction',
			'updateinfo'=>'application.controllers.actions.weibo.UpdateinfoAction',
        );
    }
	
	
	public function actionIndex1()
	{

		$this->render('index');
	}
	
	public function actionUpdateinfo1(){
	
		if(!empty($_SESSION['token']['access_token'])){
			$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );
			//$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_REQUEST['viewer'] );
			$ms  = $c->home_timeline(); // done
			$uid_get = $c->get_uid();
			$uid = $uid_get['uid'];
			$user_message = $c->show_user_by_id($uid);
			//var_dump($_SESSION);
			//var_dump($_REQUEST);
			var_dump($user_message);
			echo '<img src="'.$user_message['profile_image_url'].'" />';
			
				$model = new User;
				$user = $model->findByPk($user_message['id']);
				if(!empty($user)){
					if($user->token != $_SESSION['token']['access_token'] or $user->profile_image != $user_message['profile_image_url']){
						$user->token = $_SESSION['token']['access_token'];
						$user->profile_image = $user_message['profile_image_url'];
						$user->updatetime = time();
						$user->save();
					}
				
				}else{
					$model->id = $user_message['id'];
					$model->idstr = $user_message['idstr'];
					$model->screen_name = $user_message['screen_name'];
					$model->name = $user_message['name'];
					$model->profile_image = $user_message['profile_image_url'];
					$model->token = $_SESSION['token']['access_token'];
					$model->updatetime = time();
					
					$model->save();
					
				}
		}
		
		echo '<a href="'.$this->createUrl('site/index').'">go back</a>';
		
	
	}
	
	public function actionView()
	{
	
		echo ' you success';						
		$c = new SaeTClientV2( WB_AKEY , WB_SKEY , $_SESSION['token']['access_token'] );									
		$ms  = $c->home_timeline(); 		
		$uid_get = $c->get_uid();						
		$uid = $uid_get['uid'];				
		$user_message = $c->show_user_by_id( $uid);						
		/*var_dump($_SESSION);						
		var_dump($_REQUEST);*/						
		//var_dump($ms);
		
		if( is_array( $ms['statuses'] ) ){
			foreach( $ms['statuses'] as $item ){
				echo '<div style="padding:10px;margin:5px;border:1px solid #ccc">';
					echo $item['text'];
				echo '</div>';
				}
			}
	}

}


?>

